#!/bin/bash
#dir="/mnt"
#max_files=50
#while true; do

#	sleep 1

#done


dir="/mnt"
max_files=52

while true; do
    cd "$dir" || exit

    file_count=$(ls -1 | wc -l)

    if [[ "$file_count" -gt "$max_files" ]]; then
        while [[ "$file_count" -gt "$max_files" ]]; do
            oldest_file=$(ls -t1 | tail -n 1)
            rm "$oldest_file"
            ((file_count--))
        done
        echo "Files deleted successfully."
    else
        echo "File count within the limit."
    fi

    sleep 5
done
